package com.youdianstar.app.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.youdianstar.app.common.util.LanguageConfig
import com.youdianstar.app.common.util.StrUtil

import com.youdianstar.app.databinding.LayoutCardItemBinding
import com.youdianstar.app.entity.CardEntity
import com.youdianstar.app.util.CardIcUtil
import com.youdianstar.app.util.DataAppManager


/**
 * File: CardMethodAdapter
 * Author: Administrator Create: 2025/1/21 0021 14:11
 * Changes (from 2025/1/21 0021)
 * --------------------------------------------------
 * description:
 * ---------------------------------------------------
 *
 */
class CardMethodAdapter (val mContext: Context, val dataList: List<CardEntity>): RecyclerView.Adapter<CardMethodAdapter.ListHolder>() {
    class ListHolder(val binding : LayoutCardItemBinding) : RecyclerView.ViewHolder(binding.root)

    var languageNow :String = ""
    var symbolTx = ""
    init {
        languageNow = LanguageConfig.instance.getLanguageCode()
        symbolTx = DataAppManager.instance.symbolTx()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListHolder {
        return ListHolder(LayoutCardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false))
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ListHolder, position: Int) {
        dataList[position].let { card ->
            //根据卡类型 补充logo,
            if(StrUtil.isEmpty(card.bankName))
                holder.binding.ivCardIcon.setImageResource(CardIcUtil.getStripeDefaultIcon())
            else
                holder.binding.ivCardIcon.setImageResource(CardIcUtil.getStripeBrandIcon(card.bankName))
//            holder.binding.tvNumber.text = card.bankName
            holder.binding.tvNumber.text = "****  ****  **** " + card.bankNo
//            holder.binding.tvDes.text = mContext.getString(R.string.wallet_expiryDate)+": "+card.expireTx()
        }
        holder.binding.tvSplitLine.visibility = if (position == dataList.size-1) View.INVISIBLE else View.VISIBLE
    }
}